Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add witness hint for module_missing lint #1203

Merged

Conversation

qstommyshu
Copy link
Contributor

@qstommyshu qstommyshu commented Mar 21, 2025

Add a witness hint for module_missing, addressing #937

This witness hint is valid as use removed_mod::func; does not compile in Rust.

However, there is an edge cases where use removed_mod::inner_mod exists in the old version code, but it was replaced by use removed_mod::inner_function (but the function name is same as the previously removed inner_mod), then this witness hint may be a True Negative witness hint.

@qstommyshu qstommyshu changed the title Add witness hint for module_missing lint and update snapshot Add witness hint for module_missing lint Mar 21, 2025
@qstommyshu qstommyshu changed the title Add witness hint for module_missing lint Chore: Add witness hint for module_missing lint Mar 21, 2025
@obi1kenobi
Copy link
Owner

This witness hint is valid as use removed_mod::func; does not compile in Rust.

However, there is an edge cases where use removed_mod::inner_mod exists in the old version code, but it was replaced by use removed_mod::inner_function (but the function name is same as the previously removed inner_mod), then this witness hint may be a True Negative witness hint.

I'm not sure I understand the edge case here. Could you tell me more about it?

@qstommyshu
Copy link
Contributor Author

Sure, here is an edge case example:

Let's say this is our old version code:

pub mod bb {
	pub mod will_change_to_fn {}
}

and it is changed to:

pub mod bb {
	pub fn will_change_to_fn() {}
}

In the above case, the witness hint use bb::will_change_to_fn; will be able to compile on both version of code (which violates the definition of a witness hint), as there is no syntax differences between use a module and use a function.

One way I can think of to resolve this edge case (how to distinguish use a module or function) is to exhaustively go down to the lowest level of a module and use an element under it.

However, there is no limitation of levels for Rust nested modules, implementing such an idea probably requires recursive calls. Also, there are edge cases for this approach as well ... assuming all modules have public elements under it (i.e. a function), then use bb::will_change_to_fn::some_element; (as bb::will_change_to_fnis a module and there is a function calledsome_elementunder it) can compile butuse bb::will_change_to_fn::some_element;can not (asbb::will_change_to_fn` is a function already, it cannot nest another function inside).

Hope that makes my statement more clear, please let me know you thoughts about it.

@obi1kenobi
Copy link
Owner

Ah, I see. How about a different option then: use bb::deleted_module::*;

There's a similar edge case here: enums allow glob imports of all their variants. But clippy by default will complain about both uppercase-named modules and lowercase-named enums, so in practice this edge case will be much much more rare. I think that's probably an acceptable tradeoff for a witness hint.

What do you think?

@qstommyshu
Copy link
Contributor Author

Sounds good to me, I'll include the edge cases description as comments as well.

Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see the comments about the edge case you mentioned you might add, but this looks good already so we can add & merge those later if you'd like.

@obi1kenobi obi1kenobi merged commit b92cc58 into obi1kenobi:main Mar 25, 2025
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants